import org.junit.jupiter.api.Test;

public class test640 {
    public String solveEquation(String equation) {
        int equalIndex = equation.indexOf("=");
        //将x放在左边，数字放在右边
        int xCount = 0, numberCount = 0, start = 0, leftOrRight = 1;
        for(int i = 1; i < equation.length(); ++i){
            char cur = equation.charAt(i);
            while(cur != '+' && cur != '-' && cur != '=' && i < equation.length()){
                ++i;
                if(i == equation.length()){
                    break;
                }
                cur = equation.charAt(i);
            }
            String curStr = equation.substring(start, i);
            if(curStr.contains("x")){
                if(curStr.length() > 2){
                    curStr = curStr.substring(0, curStr.length() - 1);
                }else if(curStr.length() == 2){
                    if(curStr.charAt(0) == '-' || curStr.charAt(0) == '+'){
                        curStr = curStr.replace('x', '1');
                    }else{
                        curStr = curStr.substring(0, curStr.length() - 1);
                    }
                }else{
                    curStr = "1";
                }
                xCount += (leftOrRight * Integer.parseInt(curStr));
            }else{
                numberCount -= (leftOrRight * Integer.parseInt(curStr));
            }
            start = i;
            if(cur == '='){
                leftOrRight = -leftOrRight;
                start ++;
                if(i != equation.length() - 2){
                    i ++;
                }
            }
        }
        if(numberCount == 0 && xCount == 0){
            return "Infinite solutions";
        }else if(xCount == 0 && numberCount != 0){
            return "No solution";
        }else{
            return "x=" + String.valueOf(numberCount / xCount);
        }
    }

    @Test
    public void test(){
        String res = solveEquation("x=x");
        System.out.println(res);
    }

}
